#include "../../include/mfccs/taiic_mfcc_v3.h" 
#include <iostream>
#include <fstream>
#include <string>
#include <chrono> //计算耗时
#include <fftw3.h>

using namespace std;
using namespace Eigen;

int main()
{
    //--------------打开文件以写入--------------------
    ofstream outFile("matrix_output.txt", ios::out | ios::trunc);
    if (!outFile)
    {
        cerr << "Error opening file for writing!" << endl;
        return 1;
    }

#if TAIIC_ASR
    const char* filename = "/oem/usr/pcm/air_audio_data.pcm";
#elif ACOUSTICS_ASR
    const char* filename = "/oem/usr/pcm/001_kangheng.pcm";
#endif
    
    MatrixXd mfcc_feat_u(numFrames, num_mfcc_coef);
    VectorXd audioData = loadAudioData(filename);

    auto start = chrono::high_resolution_clock::now();
    extract_mfcc(audioData,mfcc_feat_u);
    auto end = chrono::high_resolution_clock::now();//获取结束时间点 
    chrono::duration<double> duration = end - start;//计算耗时 
    cout << "MFCC提取耗时: " << duration.count() << " 秒" << std::endl;//输出耗时 

    // 将矩阵元素写入文件  
    for (int i = 0; i < mfcc_feat_u.rows(); ++i)
    {
        for (int j = 0; j < mfcc_feat_u.cols(); ++j)
        {
            outFile << mfcc_feat_u(i, j);
            if (j < mfcc_feat_u.cols() - 1) {
                outFile << ", "; // 列之间用逗号分隔  
            }
        }
        outFile << "\n"; // 行之间换行  
    }
    outFile.close();

   return 0;
}